package com.qf.ssm.controller;


import com.qf.ssm.entity.FrontCategoryFirst;
import com.qf.ssm.entity.FrontCategoryTwo;
import com.qf.ssm.service.FrontCategoryTwoService;
import com.qf.ssm.utils.ResponseResult;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/categoryTwo")
public class FrontCategoryTwoController {
    @Resource
    private FrontCategoryTwoService frontCategoryTwoService;

    /**
     * 删除二级类目-------------展示
     * 测试通过，测试内容：
     * {
     *   "fctId": 17
     * }
     * @param fctId
     * @return
     */
    @PutMapping ("/deleteCategory")
    private ResponseResult<Integer> deleteCategory(Integer fctId){
        return ResponseResult.success(frontCategoryTwoService.deleteByPrimaryKey(fctId));
    }

    /**
     * 添加二级类目--------------展示
     * 测试通过，测试内容：
     *{
     *   "categoryName": "demoData",
     *   "categoryImg": "demoData",
     *   "status":1,
     *   "creationTime2": "2021-02-27 10:17:35",
     *   "fcfId": 2
     * }
     * 使用RequestBody注解加上时间不能正常传入，不使用RequestBody就正常
     * @param frontCategoryTwo
     * @return
     */
    @PostMapping("/newCategory")
    private ResponseResult<Integer> newCategory(FrontCategoryTwo frontCategoryTwo){

        return ResponseResult.success(frontCategoryTwoService.insert(frontCategoryTwo));


    }

    /**
     * 批量添加二级类目------------不展示
     * @param list
     * @return
     */
    @PostMapping()
    private ResponseResult<Integer> batchNewCategory(@RequestBody List<FrontCategoryTwo> list){
        return ResponseResult.success(frontCategoryTwoService.batchInsert(list));
    }

    /**
     * 通过分类名称和时间段查询--------展示
     *测试通过，测试内容：
     *{
     *   "fctName": "潮流达人",
     *   "frontDate": "2021-02-22 09:08:14",
     *   "afterDate": "2021-02-27 09:08:14"
     * }
     */
    @GetMapping("queryNameAndDate")
    private ResponseResult<List<FrontCategoryTwo>> queryNameAndDate(String fctName, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
            Date frontDate, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date afterDate) {
        return ResponseResult.success(frontCategoryTwoService.selectNameAndDate(fctName, frontDate, afterDate));
    }

    /**
     * 编辑二级类目----------------展示
     *测试通过，测试内容：
     *{
     *   "fctId": 7,
     *   "categoryName": "demoData",
     *   "categoryImg": "demoData",
     *   "status": 1,
     *   "creationTime2": "2021-02-27 10:39:54",
     *   "fcfId": 4
     * }
     */
    @PutMapping("/editCategory")
    private ResponseResult<Integer> editCategory(FrontCategoryTwo frontCategoryTwo){
        return ResponseResult.success(frontCategoryTwoService.updateByPrimaryKey(frontCategoryTwo));
    }
}
